/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package model;

import java.util.List;
import javax.swing.table.AbstractTableModel;
import constants.*;
/**
 *
 * @author Đức Trung
 */
public class CustomerModel extends AbstractTableModel {
    dao.Customer customer = new dao.Customer();
    List<entity.Customer> list ;
    public CustomerModel(List<entity.Customer> list){
        this.list=list;
    }
    public final static String[] columnNames = {
        "STT","Mã khách hàng","Họ tên","Tuổi","Giới tính","CMND","Địa chỉ","Số điện thoại","Quốc tịch","Tình trạng"
    };
    public int getRowCount() {
        return list.size();
    }
    public int getColumnCount() {
        return columnNames.length;
    }
 
    public Object getValueAt(int row, int col) {
           //Widget widget = (Widget) list.get(row);
        switch(col){
            case 0: return row+1;
            case 1: return list.get(row).getId();
            case 2: return list.get(row).getName();
            case 3: return list.get(row).getAge();    
            case 4: 
                if(list.get(row).getGender()==Constants.MALE)
                    return "Nam";
                else
                    return "Nữ";
            case 5: return list.get(row).getId_card();
            case 6: return list.get(row).getAddress();
            case 7: return list.get(row).getPhone();
            case 8: return list.get(row).getCountry();
            case 9: return Constants.BOOK_NAME[list.get(row).getInfo().getStatus()];
            default: return null;  
            }
    }

    public String getColumnName(int columnIndex) {
        return columnNames[columnIndex];
    }
        public void refesh(){
        fireTableDataChanged();
    }
      public void removeRow(int row) {
        list.remove(row);
        fireTableDataChanged();
    }
    public void insertList(entity.Customer e){
        list.add(e);
        fireTableDataChanged();       
    }
    public void editList(int index,entity.Customer e){
        list.remove(index);
        list.add(index, e);
        fireTableDataChanged();    
    }
}
